package thread;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.Timer;
import java.util.TimerTask;

public class SleepDemo {
    public static void main(String[] args) throws IOException {
//        System.out.println("start");
//        try {
//            Thread.sleep(5000L);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
//        System.out.println("end");
        //用sleep（）  阻塞线程的执行
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入倒计时的秒数：");
//        int sec=sc.nextInt();
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int sec=Integer.parseInt(br.readLine());
        while(sec!=0){
            System.out.println("剩余时间"+sec+"s");
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            sec--;
        }
        System.out.println("时间到");
//            Scanner sc=new Scanner(System.in);
//            int seco=sc.nextInt();
//        Timer tim=new Timer();
//        tim.schedule(new TimerTask() {
//            @Override
//            public void run() {
//                System.out.println(seco+"s");
//            }
//        },0,1000);

    }
}
